<template>
  <section class="benefit-main">
    <div class="red-envelopes" v-show="!currentIndex">
      <div class="top">
        <span class="left"
          >有
          <i>{{ redEnvelopes.length }}</i>
          个红包即将过期
        </span>
        <span class="right" @click="handleSkipHbDescription"> 红包说明 </span>
      </div>
      <div class="center">
        <red-envelopes-item
          v-for="(item, index) in redEnvelopes"
          :key="index"
          :item="item"
          :index="index"
        />
        <div class="history" @click="handleSkipHbHistory">
          <span>查看历史红包</span>
          <span class="arrow"></span>
        </div>
      </div>
      <div class="bottom">
        <span @click="handleSkipExchange">兑换红包</span>
        <span @click="handleSkipCommend">推荐有奖</span>
      </div>
    </div>
    <div class="cash-coupon" v-show="currentIndex">
      <div class="tips" @click="handleSkipCoupon">
        <span class="explain">商家代金券说明</span>
      </div>
      <div class="voucher">
        <img src="~assets/img/profile/voucher.png" alt="" />
        <p class="tips-1">无法使用代金券</p>
        <p class="tips-2">非客户端或客户端版本过低</p>
        <p class="tips-3" @click="handleSkipDownload">下载或升级客户端</p>
      </div>
    </div>
  </section>
</template>

<script>
import RedEnvelopesItem from "./childComps/RedEnvelopesItem";
export default {
  data() {
    return {
      currentIndex: 0,
    };
  },
  props: {
    redEnvelopes: {
      type: Array,
      default() {
        return [];
      },
    },
  },
  mounted() {
    this.$bus.$on("handleSwitchTabControl", (index) => {
      this.currentIndex = index;
    });
  },
  methods: {
    handleSkipHbDescription() {
      this.$router.push("/benefit/hbDescription");
    },
    handleSkipHbHistory() {
      this.$router.push("/benefit/hbHistory");
    },
    handleSkipExchange() {
      this.$router.push("/benefit/exchange");
    },
    handleSkipCoupon() {
      this.$router.push("/benefit/coupon");
    },
    handleSkipDownload() {
      this.$router.push("/download");
    },
    handleSkipCommend() {
      this.$router.push('/benefit/commend')
    }
  },
  components: {
    RedEnvelopesItem,
  },
};
</script>
<style lang="less" scoped>
.benefit-main {
  padding: 20px;
  font-size: 12px;
  .red-envelopes {
    .top {
      display: flex;
      justify-content: space-between;
      i {
        font-style: normal;
        color: #ff5340;
      }
      .right {
        position: relative;
        color: #3190e8;
        &::before {
          content: "";
          position: absolute;
          top: 50%;
          right: 50px;
          width: 15px;
          height: 15px;
          background-image: url("~assets/img/profile/description.png");
          background-size: 100% 100%;
          transform: translateY(-60%);
        }
      }
    }
    .center {
      .history {
        text-align: center;
        margin: 30px auto;
        .arrow {
          position: relative;
          top: -1px;
          display: inline-block;
          width: 6px;
          height: 6px;
          border-top: 2px solid #c5c5c5;
          border-right: 2px solid #c5c5c5;
          margin-left: 5px;
          transform: rotate(45deg);
        }
      }
    }
    .bottom {
      display: flex;
      justify-content: space-around;
      position: fixed;
      right: 0;
      bottom: 0;
      left: 0;
      background-color: #fff;
      span {
        padding: 20px;
      }
    }
  }
  .cash-coupon {
    text-align: right;
    .tips {
      position: relative;
      color: #3190e8;
      & ::before {
        content: "";
        position: absolute;
        top: 50%;
        right: 90px;
        width: 15px;
        height: 15px;
        background-image: url("~assets/img/profile/description.png");
        background-size: 100% 100%;
        transform: translateY(-60%);
      }
    }
    .voucher {
      margin-top: 120px;
      text-align: center;
      img {
        width: 140px;
      }
      .tips-1 {
        margin-top: 10px;
        font-size: 14px;
      }
      .tips-2 {
        margin: 10px 0;
        color: #999999;
      }
      .tips-3 {
        display: inline-block;
        padding: 10px;
        border-radius: 5px;
        background-color: #56d176;
        color: #fff;
      }
    }
  }
}
</style>